<?php
namespace ZHMVC\DB\MANAGER;
if (! isset($_SESSION)) {
    session_start();
}
include (dirname(dirname(__FILE__)) . "/zhconfig/Config.php");
include (ZH_PATH . DS . MANAGERFPATH . DS . 'islogin' . ZH);

$isp = new \ZHMVC\D\MANAGER\isPermission();
$isper = $isp->getPermission();
$_curlid = $isp->getCUrl();
$c = new \ZHCONFIG\ZhConfig();
$db_pre = $c->getDbPre();

include (ZH_PATH . DS . MANAGERFPATH . DS . 'top1' . ZH);
?>
<script type="text/javascript" src="/common/hui/lib/jquery/1.9.1/jquery.min.js"></script>
<div class="wap-container">
	<nav class="breadcrumb" style="background-color: #fff; padding: 0 24px">
		<a class="btn btn-success radius f-l" style="line-height:1.6em;margin-top:3px" href="javascript:;" onClick="location='/<?php echo MANAGERFPATH;?>/admin_menutype.php';" class="btn btn-primary radius">导航类型管理</a>
		<a class="btn btn-success radius f-r"
			style="line-height: 1.6em; margin-top: 3px"
			href="javascript:location.replace(location.href);" title="刷新"><i
			class="Hui-iconfont">&#xe68f;</i></a>
	</nav>
<?php
$action=SafeRequest(getPGC("atcion"),0);
switch ($action) {
    case "save":
        save();
        break;
    case "add":
        add();
        break;
    case "del":
        del();
        break;
    default:
        main();
}
            
function main()
{
    $classid=SafeRequest(getPGC("classid"),0);
    $currentpg =1;
    if(count($_GET)>0)
    {
        if(isset($_GET['pg']))
        {
            $currentpg = $_GET['pg'];
        }
    }
?>
<article class="Hui-admin-content clearfix">
<div class="panel mt-20">
	<div class="panel-body">
	<div class="clearfix">
			<span class="f-l">
				<a href="javascript:;" onClick="location='?atcion=add';" class="btn btn-primary radius"><i class="Hui-iconfont">&#xe600;</i> 新增</a>
			</span>
	</div>
	<div class="clearfix mt-20">
	<table class="table table-border table-bordered table-hover table-bg table-sort">
		<thead>
            <tr class="text-c">
                <th>Id</th>
                <th>菜单名称</th>
                <th>类别</th>
				<th>是否导航</th>
				<th>栏目排序</th>
        		<th>执行文件</th>
				<th>操作</th>
        	</tr>
    	</thead>
    <tbody>
<?php
    // 获取所有的栏目
    $classid=0;
    $map="";
    $rs = new \ZHMVC\D\Frontmenu();
    $datas = $rs->getAll($map);
    // print_r($datas);
    $newsfun = new \ZHMVC\B\TOOL\Clsfun($classid);
    $newsfun->data1arr($datas, 0, 0, 0);
    echo $newsfun->getData1();
    $newsfun = null;
    $rs = null;
?>
    </tbody>
</table>
					</div>
				</div>
			</div>
</article>
<?php
}
            
function add()
{
    $currentpg =1;
    if(count($_GET)>0)
    {
        if(isset($_GET['pg']))
        {
            $currentpg = $_GET['pg'];
        }
    }
    $postid=SafeRequest(getPGC("postid"),0);
            
	if(($postid!="") && ($postid!="0"))
	{
	    $rs = new \ZHMVC\D\Frontmenu();
		$data=$rs->getOne($postid);
		$rows=$rs->getRows();
		If($rows!=0)
		{
            $ilistid=$postid;
            $name=$data['name'];
            $subname=$data['subname'];
            $fid=$data['fid'];
            $ordernum=$data['ordernum'];
            $ismenu=$data['ismenu'];
            $phpfile=$data['phpfile'];
            $info=$data['info'];
            $tubiao=$data['tubiao'];
            $datu=$data['datu'];
            $moduleid=$data['moduleid'];
            $aid=$data['aid'];
            $htmlfile=$data['htmlfile'];
            
		}
		else
		{
            $ilistid="";
            $name='';
            $subname='';
            $fid='';
            $ordernum='0';
            $ismenu='是';
            $phpfile='';
            $info="";
            $tubiao="";
            $datu="";
            $moduleid="0";
            $aid="";
            $htmlfile="";
        }
	}
    else
    {
       $ilistid="";
       $name='';
       $subname='';
       $fid='';
       $ordernum='0';
       $ismenu='是';
       $phpfile='';
       $info="";
       $tubiao="";
       $datu="";
       $moduleid="0";
       $aid="";
       $htmlfile="";
    }
?>
<div class="panel">
	<div class="panel-body">
         <!-- 表单 -->
            <form name="PForm" id="PForm" method="post" action="?atcion=save&postid=<?php echo $postid; ?>&pg=<?php echo $currentpg;?>" class="form form-horizontal">
                			
                            <div class="row clearfix">
            					<label class="form-label col-xs-4 col-sm-3">菜单名称：</label>
            					<div class="form-controls col-xs-8 col-sm-9">
            						<input type="text" id="name" name="name" class="input-text" placeholder="" 
                                    value="<?php echo $name; ?>" />
            					</div>
            				</div>
            				<div class="row clearfix">
            					<label class="form-label col-xs-4 col-sm-3">菜单名称别名：</label>
            					<div class="form-controls col-xs-8 col-sm-9">
            						<input type="text" id="subname" name="subname" class="input-text" placeholder="" 
                                    value="<?php echo $subname; ?>" />
            					</div>
            				</div>

							<div class="row clearfix">
                				<label class="form-label col-xs-4 col-sm-3">所属分类：</label>
                					<div class="form-controls col-xs-8 col-sm-9">
                		             <select name="fid" class="select">
                                        <option value="0">==根栏目==</option>
                                        <?php 
                                        //获取所有的栏目
                                        $rs1=new \ZHMVC\D\Frontmenu();
                                        $datas=$rs1->getAll();
                                        $newsfun=new \ZHMVC\B\TOOL\Clsfun(0);
                                        $newsfun->data1option($datas,0,0,$fid);
                                        echo $newsfun->getData2();
                                        $newsfun=null;
                                        $rs1=null;
                                        ?>								
    									</select>
                					</div>
                		  	</div>
            				<div class="row clearfix">
            					<label class="form-label col-xs-4 col-sm-3">是否在菜单中显示：</label>
            					<div class="form-controls col-xs-8 col-sm-9">
            					<div class="radio-box">
                                    <input name="ismenu" type="radio" value="是" id="ismenu-1"  <?php
                                    if ($ismenu == "是") { echo "checked";}?> />
        							<label for="ismenu-1">是</label>
                                    </div>
                                    <div class="radio-box">
                                    <input name="ismenu" type="radio" value="否" id="ismenu-0"  <?php
                                    if ($ismenu == "否") { echo "checked";}?> />
        							<label for="ismenu-0">否 </label>
                                </div>
  
            					</div>
            				</div>
            				
            				<div class="row clearfix">
            					<label class="form-label col-xs-4 col-sm-3">栏目排序：</label>
            					<div class="form-controls col-xs-8 col-sm-9">
            					<input type="text" id="ordernum" name="ordernum" class="input-text" placeholder="0" 
                                    value="<?php echo $ordernum; ?>" />
            		             
            					</div>
            				</div>
            			
                        	<script language="javascript">
                            //打开选择理由窗口的函数
                        	function openphpfileWin(itype)
                            {     
                                var srczhaiyaoFile = "/common/tool/showphpfile.php?moduleid=<?php echo $moduleid;?>&itype="+itype;
                                window.open(srczhaiyaoFile,"_blank","toolbar=no, location=yes, directories=no, status=no, menubar=yes, scrollbars=yes, resizable=no, copyhistory=yes, width=800, height=600")
                            }
                            </script>
            				<div class="row clearfix">
            					<label class="form-label col-xs-4 col-sm-3">执行文件：</label>
            					<div class="form-controls col-xs-4 col-sm-5">
            					<input type="text" id="phpfile" name="phpfile" readonly class="input-text" placeholder="请输入执行文件" 
                                    value="<?php echo $phpfile; ?>" />
            					</div>
            					<label class="form-label col-xs-4 col-sm-4">
            						<a href="javascript:;"
        						onClick="openphpfileWin('phpfile');" class="btn btn-primary radius"><i
        							class="Hui-iconfont">&#xe600;</i> 查找</a>
            					</label>
            				</div>	
            				
            				<script language="javascript">
                            //打开选择理由窗口的函数
            				function openhtmlfileWin(itype)
                            {       
                                var srczhaiyaoFile = "/common/tool/showhtmlfile.php?itype="+itype;
                                window.open(srczhaiyaoFile,"_blank","toolbar=no, location=yes, directories=no, status=no, menubar=yes, scrollbars=yes, resizable=no, copyhistory=yes, width=800, height=600")
                            }
                            </script>
            				<div class="row clearfix">
            					<label class="form-label col-xs-4 col-sm-3">模板文件：</label>
            					<div class="form-controls col-xs-4 col-sm-5">
            					<input type="text" id="htmlfile" name="htmlfile" readonly class="input-text" placeholder="请输入执行文件" 
                                    value="<?php echo $htmlfile; ?>" />
            					</div>
            					<label class="form-label col-xs-4 col-sm-4">
            						<a href="javascript:;"
        						onClick="openhtmlfileWin('htmlfile');" class="btn btn-primary radius"><i
        							class="Hui-iconfont">&#xe600;</i> 查找</a>
            					</label>
            				</div>	
            				
            				<div class="row clearfix">
            					<label class="form-label col-xs-4 col-sm-3">描述：</label>
            					<div class="form-controls col-xs-8 col-sm-9">
                                    <textarea name="info" class="textarea" style="height:100px"><?php echo $info; ?></textarea>
            					</div>
            				</div>
            				
            				<div class="row clearfix">
            					<label class="form-label col-xs-4 col-sm-3">图标：</label>
            					<div class="form-controls col-xs-8 col-sm-9">
            						<input class="input-text" type="text" name="tubiao" id="tubiao" readonly value="<?php echo $tubiao; ?>">
            						<iframe name="up" frameborder="0" width="500" height="100" scrolling="no"
            						src="/common/tool/upload/uploadfile.php?formname=PForm&frominputname=tubiao"></iframe>
                                    <?php If($tubiao) { ?>
                                         <a href="<?php echo $tubiao; ?>" target="_blank"> 
                                             <img src="<?php echo $tubiao; ?>" alt="" height="60" width="90" />预览图片
                                         </a>
                                    <?php } ?>
                        		</div>
            				</div>
				
            				<div class="row clearfix">
            					<label class="form-label col-xs-4 col-sm-3">大图：</label>
            					<div class="form-controls col-xs-8 col-sm-9">
            						<input class="input-text" type="text" name="datu" id="datu" readonly value="<?php echo $datu; ?>">
            						<iframe name="up" frameborder="0" width="500" height="100" scrolling="no"
            						src="/common/tool/upload/uploadfile.php?formname=PForm&frominputname=datu"></iframe>
                                    <?php If($datu) { ?>
                                         <a href="<?php echo $datu; ?>" target="_blank"> 
                                             <img src="<?php echo $datu; ?>" alt="" height="60" width="90" />预览图片
                                         </a>
                                    <?php } ?>
            					</div>
            				</div>
            				
          				<div class="row clearfix">
							<div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-2">
								<button onClick="article_save_submit();" class="btn btn-primary radius" type="submit"><i class="Hui-iconfont">&#xe632;</i> 保存</button>
								<button onClick="layer_close();" class="btn btn-default radius" type="button">&nbsp;&nbsp;取消&nbsp;&nbsp;</button>
							</div>
						</div>
            </form>
          <!-- 表单 -->
          </div>
    	</div>
<?php
}
            
function save()
{
	$postid=SafeRequest(getPGC("postid"),0);
    $currentpg =1;
    if(count($_GET)>0)
    {
        if(isset($_GET['pg']))
        {
            $currentpg = $_GET['pg'];
        }
    }  

    $name=SafeRequest(getPGC("name"),0);
    $htmlfile=SafeRequest(getPGC("htmlfile"),0);
    $fid=SafeRequest(getPGC("fid"),0);
    if($fid=="") $fid="0";
    $ismenu=SafeRequest(getPGC("ismenu"),0);
    $ordernum=SafeRequest(getPGC("ordernum"),0);
    $phpfile=SafeRequest(getPGC("phpfile"),0);
    $subname=SafeRequest(getPGC("subname"),0);
    $info=SafeRequest(getPGC("info"),0);
    $tubiao=SafeRequest(getPGC("tubiao"),0);
    $datu=SafeRequest(getPGC("datu"),0);
    
    if(($postid!="") && ($postid!="0"))
    {
        $rs = new \ZHMVC\D\Frontmenu();
        $rs->update($postid, $fid, $name, $subname, $ismenu, $ordernum, $phpfile, $info, $datu, $tubiao, $htmlfile);
        $ilistid=$postid;
    }
    Else
    {
        $rs = new \ZHMVC\D\Frontmenu();
        $data=$rs->add($fid, $name, $subname, $ismenu, $ordernum, $phpfile, $info, $datu, $tubiao, '0', '0', $htmlfile);
        $ilistid=$rs->getLastId();
    }
     
	echo "<script>alert('更新成功');window.location.href='admin_frontmenu.php?pg=".$currentpg."';</script>";
}
            
function del()
{
    $postid=SafeRequest(getPGC("postid"),0);
    $currentpg =1;
    if(count($_GET)>0)
    {
        if(isset($_GET['pg']))
        {
            $currentpg = $_GET['pg'];
        }
    } 
	if(($postid!="") && ($postid!="0"))
	{
	    $rs = new \ZHMVC\D\Frontmenu();
		$rs->delete($postid);
		echo "<script>alert('更新成功');window.location.href='admin_frontmenu.php?pg=".$currentpg."';</script>";
	}
}
?>
</div>
<?php 
include (ZH_PATH . DS . MANAGERFPATH . DS . "foot2" . ZH);
?>
</body>
</html>
